package com.jeecms.wicool.dao.product.impl;

import java.util.List;

import org.springframework.stereotype.Repository;
import com.jeecms.common.hibernate3.Finder;
import com.jeecms.common.hibernate3.HibernateBaseDao;
import com.jeecms.common.page.Pagination;
import com.jeecms.wicool.dao.product.ProductSkuDao;
import com.jeecms.wicool.entity.product.ProductSku;

@Repository
public class ProductSkuDaoImpl extends HibernateBaseDao<ProductSku, Integer>
		implements ProductSkuDao {

	@Override
	protected Class<ProductSku> getEntityClass() {
		// TODO Auto-generated method stub
		return ProductSku.class;
	}
	@Override
	public Pagination getPage(Integer productId,
			int pageNo, int pageSize) {
			Finder f = Finder.create("select bean from ProductSku bean where 1=1 ");
			
			if (null!=productId){
				f.append(" and bean.product.id = :productId");
				f.setParam("productId",productId);
			}
			f.append(" order by bean.id desc");
			return find(f, pageNo, pageSize);
	}
	@Override
	public ProductSku findById(Integer id) {
		ProductSku entity = get(id);
		return entity;
	}
	@Override
	public ProductSku save(ProductSku bean) {
		getSession().save(bean);
		return bean;
	}
	@Override
	public ProductSku deleteById(Integer id) {
		ProductSku entity = super.get(id);
		if (entity != null) {
			getSession().delete(entity);
		}
		return entity;
	}
	@Override
	public List<ProductSku> getListProductSku(Integer productId) {
		Finder f = Finder.create("select bean from ProductSku bean where bean.product.id = '"+ productId+"'");
		return find(f);
	}
}